Repository navigation
feat(assistant): edit and resend the last stopped message - #424
Zhangbo-cn wants to merge 11 commits into
Conversation
…ab#375) A stopped turn can be revised in place: the new attempt records the turn it replaces, so the active path follows that chain instead of slicing messages positionally. Project changes and accepted jobs are preserved, and a snapshot of the replaced attempt's tool records rides on the new turn. Server: - Turn gains revisionOf and expectedRevision; conversation.json keeps an incrementing revision so a stale view cannot overwrite a newer one. - active_messages() replaces the positional slicing that fed the runtime context; the superseded request and its partial reply leave the active path but stay in history. - Validation inside the begin transaction: expected revision, then the target turn, then its terminal status, then the duplicate id. - inherited_jobs() keeps the idempotency key for every replaced call and resolves the job record when one was accepted. Client: - Editing a stopped message fills the composer with its text, references and skills, and leaves the conversation untouched until the server accepts. - pendingTurnId in sessionStorage keeps one operation identity across retries of an uncertain edit. - Inherited jobs render in a collapsed section. Also tolerate plain-text stdout from a harness: Claude Code prints an unrecognized-model warning between JSON events, which failed the whole turn on a parse error.
|
Two checks failed; neither comes from this change.
That test drives I read this as a timing flake on a 20 s wait after video rendering. I cannot rerun the job myself (no admin rights), so if a maintainer can rerun
Everything else is green: |
|
On the new CodeQL alert: I cannot see the alert details — To narrow it down, here is what the diff can and cannot contain. The TypeScript changes are type declarations plus React render code, all escaped by React; there is no store.setItem(`opendirector.chat.revision.${conversationId}`, id)That is an operation identity, not a credential, and it lives in The Python changes read So I would expect the alert to be a false positive or to sit in code I did not touch, but I am guessing without the rule id. Happy to fix it once I know what it points at. |
|
@yefuyou — your boundary matches what I built, and #374 is already on What matches. The original user message id stays the turn id, and the new attempt gets its own id, so the two never mix. Refresh links are a separate field ( job.agentRunId == revision_of # same filter as turn_jobs()
agent_command_id(turn, call_id) # same derivationWhere I diverged. Rather than let the new attempt query "inheritedJobs": [{"commandId": "...", "callId": "...", "name": "...",
"jobId": "..."|null, "status": "...", "asset": {...}|null}]
My reason was that the composer needs to show what the previous attempt already submitted before resending, and a snapshot makes that a single read with the message. The cost is duplication: if a Job's status changes after the snapshot, the snapshot is stale and only the endpoint is authoritative. The question. Do you want the snapshot kept, or removed in favour of the client calling Your point that the endpoint does not decide reuse-or-resubmit also matches: nothing in my change auto-reuses. The snapshot is informational; the decision stays with the attempt. |
1 similar comment
|
@yefuyou — your boundary matches what I built, and #374 is already on What matches. The original user message id stays the turn id, and the new attempt gets its own id, so the two never mix. Refresh links are a separate field ( job.agentRunId == revision_of # same filter as turn_jobs()
agent_command_id(turn, call_id) # same derivationWhere I diverged. Rather than let the new attempt query "inheritedJobs": [{"commandId": "...", "callId": "...", "name": "...",
"jobId": "..."|null, "status": "...", "asset": {...}|null}]
My reason was that the composer needs to show what the previous attempt already submitted before resending, and a snapshot makes that a single read with the message. The cost is duplication: if a Job's status changes after the snapshot, the snapshot is stale and only the endpoint is authoritative. The question. Do you want the snapshot kept, or removed in favour of the client calling Your point that the endpoint does not decide reuse-or-resubmit also matches: nothing in my change auto-reuses. The snapshot is informational; the decision stays with the attempt. |
|
Thanks for checking this with me. From the #374 Turn → Job lineage side, my recommendation is option B: keep the existing That keeps message revisions ( For how the inherited Job information should appear in the composer, I'd defer to the product/UX direction for #375. This is my architectural preference rather than a decision on the final UI. |
|
Request: review on the current base, not a retry of the 2026-11-21 attempt — @FayeSpica, would you take this one? Background, since the red CI was not caused here:
I have merged Two reasons not to retry the old attempt instead:
The isolated suite is also intermittent on this runner: main's own Release checks passed at 2026-11-22T16:06Z before #441, and two other branches in the same window failed different isolated cases with bare timeouts ( Local checks after the merge: What I am asking for:
|
# Conflicts: # src/canvas/useAssistantChat.ts
…w turn An edit/resend wrote the inherited jobs' status, asset and error into the new user message. Those are facts about the job record, not about the call, so the copy stopped being true as soon as a job progressed: expanding the block later reported the status from the moment of the write. Persist the ids only -- command id, call id, name and job id -- because that is what cannot change and what a retry needs to decide between reusing a job and submitting again. A reader that wants the current state looks the job up by id; a missing lookup is not proof that resubmitting is safe, so the id stays. The block also counted every inherited call as "already submitted", including calls that never produced a job. The count now covers the submitted ones and a call without a job is marked as such.
07d3e42 to
621bc94
Compare
# Conflicts: # apps/api/src/opendirector_api/agent.py
|
@yefuyou — I took option B for the job state, with one part of option A kept, and your caveat is why. Job state is no longer persisted. The snapshot written into the new message used to carry The ids stay, because of what you wrote about the empty lookup. "An empty or failed lookup should not by itself be treated as proof that retrying a side-effectful submission is safe" — that is exactly the decision this data feeds: One bug this surfaced, now fixed. The block header said "Tasks already submitted (N)" but counted every inherited call, including calls that never produced a job. The count now covers only calls with a Tests. The branch is no longer conflicting. Merged One thing I will not claim: an earlier |
13fdcd5 to
20a84a6
Compare
Port turn revision into the queue/admission chain: the active path is derived from revisionOf links, queue admission validates expectedRevision, and dispatch increments the conversation revision.
# Conflicts: # scripts/ci/python_shards.json
|
Conflicts with Internal audit score: 100/100. @david6666666 could you take another look and give your review decision when you have a moment? |
david6666666
left a comment
There was a problem hiding this comment.
COMMENT(非表决) 574ddd1 Refs #375
改写后旧内容不再进入 fixture 里的新一轮上下文,这点做对了。我下载核对了 6 张中英文截图;它们能证明编辑入口和结果,没覆盖「服务端已接受、客户端没收到确认」的重试。PR 说会重用原 ID,但当前提交流程无论有没有收到确认都会清掉它。请先用 acceptance 结果决定清理时机,再补一段停止→编辑→重发→刷新/重试的视频。技术结论:需修改。
Ran: 回读同 SHA Release及本 PR 的变更与证据。Not run: 未独立执行 PR 代码或调用真实 provider。
47/100(范围/正确性/验证/主张证据/简洁度:3/1/2/0/3)。
Base 322f98c317322c1ac12541093719c890507b51b0 · Head 574ddd1a8f5e2eb944f3750eb74cd25dfca0cc4f。
Dot,代表 @david6666666。
| ); | ||
| }); | ||
| if (revising && input.conversationId) | ||
| rememberPendingTurnId(input.conversationId); |
There was a problem hiding this comment.
这里等待 follow() 结束不等于服务端确认接受:follow() 自己会处理网络错误,拒绝的 SSE 也能正常返回。现在两种情况都会删掉 pending ID 并退出编辑。建议只有确认该 ID 已持久化时才清理;给“请求已经被接收、连接在 start 前断开”的场景补一个回归,核对重试仍使用同一个 ID。
A stopped turn can be edited and resent in place. The new attempt records the turn it replaces, and the active conversation path is derived by following that chain rather than by slicing
messagespositionally.Design decisions
revisionOfis the only new relationship field. The new user message carries it alongsidemodelandruntime; the active path is derived by walking the chain, with non-terminal nodes considered superseded. No secondsupersededByfield, so there is one source of truth and no implicit ordering rules — the exact class of bug that positional slicing (messages[:-2]) produced.expectedRevisionguards concurrent writes.conversation.jsonkeeps an incrementingrevision;begincarriesexpectedRevisionand a mismatch returns a conflict with the current revision. Validation order inside one transaction: revision →revisionOfvalidity → target turn terminal status → duplicate message id.Scope stays on the newest turn. Editing is offered only for the newest user message whose reply is
stoppedorinterrupted, and a turn can only be revised once.The session is rebuilt from the revised history. The old native session is discarded and the original working directory is kept, uniformly across runtimes.
Accepted jobs are carried forward. The new turn gets an
inheritedJobssnapshot.commandId(the idempotency key) is always present;jobIdis resolved from the project snapshot when the submission was actually accepted, sojobId: nullmeans "this call never produced a job" rather than "unknown". The UI shows this in a collapsed section.Client keeps one operation identity.
pendingTurnIdinsessionStorage(keyed by conversation) is reused when retrying an uncertain edit, and cleared on acceptance.Changes
apps/api/src/opendirector_api/agent.py—Turn.revisionOf/expectedRevision,active_messages(),revision_error(),inherited_jobs(), revision counter, transactional validation.src/backend/chat.ts,src/canvas/chatTurnRequest.ts,src/canvas/useAssistantChat.ts,src/canvas/AssistantPanel.tsx,assistant-panel.css— editing state, composer fill, inherited jobs, copy in en-US and zh-CN.tests/browser/assistant_revision.mjsand a manifest entry — the edit-and-resend path through the isolated fixture..gitignorenow ignoresnode_modulesas a file as well as a directory, and the sharednode_modulessymlink is no longer tracked. It was committed by accident; a trailing slash makes the pattern match directories only, not a symlink.The revision guard is now actually sent
The server rejects a stale
expectedRevisionand the request builder carries it, but thestartevent rebuilt the client conversation withoutrevision, so the guard was never exercised from the UI.useAssistantChatnow keepsevent.conversation.revision.tests/browser/assistant_revision.mjsstops a reply, edits it, and asserts that the POST carriesrevisionOfand a numericexpectedRevision, and that the revised attempt's runtime context excludes the replaced request. Removing the one line that keepsrevisionfails the test at "the edit carries the conversation revision", so it is a regression guard rather than a description of the current state.Verification
pytest tests/test_assistant_revision.py— 10 passed on this tip. Covers the chain-derived active path, rejecting an unrelated or non-newest turn, single revision, staleexpectedRevision, concurrent running turn (real 409), reload, attachment preservation through a real upload, and the job snapshot.node --test tests/assistantRevision.test.ts— 3 passed.tests/browser/assistant_revision.mjs— 12 checks pass againstcreation_server.py --assistant-fixtureplus Vite on this branch (creation-test-health.isolated === true): a held reply is stopped, the composer is filled with its text, cancel restores the empty draft, an edit is sent, both attempts stay in history, and the new attempt's context contains the new text but not the replaced one.npx tsc --noEmit— clean.npm test— 1117 passed / 1 failed. The failure istests/browserHost.test.ts's PATH probe, which also fails onmainin this environment (python3resolves/usr/bin/nodefrom a PATH the test expects to be stripped); it does not touch assistant code.npm run check:i18n— 3864 keys, 0 problems.npm run check:browser-manifest— 113 entries OK.Earlier manual runs on Windows with a local server driven over HTTP:
work\keep.txt, stop recordedstopped, revised turn repliedNEW-MARK, context contained only the revised requestDEEPSEEK_API_KEYwas present in the launching environmentThe Claude Code stdout diagnostic that these runs needed is a separate change (
#568,Fixes #567) and is not part of this diff.Evidence
Captured with the isolated fixture: before is
origin/mainat8cdf67ec, after isba6ba6c3, the feature tip.574ddd1amergesorigin/mainat322f98c3to resolve the shard-manifest conflict and does not change the edit-and-resend flow; Release checks are green on574ddd1a. The fixture reply is held at the same point in every run.main)Before: a stopped reply has no way to revise it. Editing: "Edit and resend" sits on the stopped turn, the editing notice and cancel control appear above the composer, and the composer holds the original text. After: both attempts stay inspectable — the first stays stopped, the revised attempt completes, and the replaced request is no longer on the active path.
Not done
Refs #375. Parent roadmap #261.